package com.lupan.tomcatStudy.jndi.service;

import com.lupan.tomcatStudy.jndi.common.EmailUtil;

import javax.mail.MessagingException;
import javax.naming.NamingException;

/**
 * 说明：
 *
 * @author lupan
 * @version 2016/6/27 12:48
 */
public class EmailService {

    private EmailService() {

    }

    private static volatile EmailService singleton;

    public static EmailService getInstance() {
        if (singleton == null) {
            synchronized (EmailService.class) {
                if (singleton == null) {
                    singleton = new EmailService();
                }
            }
            return singleton;
        } else {
            return singleton;
        }
    }


    /**
     * 发送邮件
     * @param addresses to邮箱地址
     * @param subject 主题
     * @param content 内容
     */
    public void sendEmail(String[] addresses, String subject, String content) {
        try {
            EmailUtil.sendEmail(addresses,subject,content);
        } catch (NamingException e) {
            System.out.println(e.toString());
            e.printStackTrace();
        } catch (MessagingException e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }
}
